home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / sndblst4.zip / RWAVE.C < prev    next >
Text File  |  1993-12-11  |  3KB  |  128 lines

  1.  
  2. //------------------------------------------------------------------------------
  3. // Copyright (c) David Welch, 1993
  4. //------------------------------------------------------------------------------
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <dos.h>
  9.  
  10. #include "sb.h"
  11.  
  12. unsigned char ca;
  13. unsigned short ra;
  14. unsigned long la;
  15. FILE *fp;
  16. unsigned char gstring[80];
  17.  
  18. unsigned char major;
  19. unsigned char minor;
  20.  
  21. //.WAV stuff
  22. unsigned long rID;
  23. unsigned long rLen;
  24. unsigned long wID;
  25. unsigned long fID;
  26. unsigned long fLen;
  27. unsigned long fNext;
  28. unsigned short wFormatTag;
  29. unsigned short nChannels;
  30. unsigned short nSamplesPerSec;
  31. unsigned short nAvgBytesPerSec;
  32. unsigned long dID;
  33. unsigned long dLen;
  34. //------------------------------------------------------------------------------
  35. void main ( int argc, char *argv[] )
  36. {
  37.     if(argc==1)
  38.     {
  39.         printf("RWAVE [d:][path]filename[.WAV] [samplerate]\n");
  40.         exit(1);
  41.     }
  42.     if(argc==2)
  43.     {
  44.         nSamplesPerSec=12000;
  45.         printf("Default sample rate of %u Hz will be used\n",nSamplesPerSec);
  46.     }
  47.     if(argc>=3)
  48.     {
  49.         nSamplesPerSec=atoi(argv[2]);
  50.         printf("Samples Per Second %u\n",nSamplesPerSec);
  51.     }
  52.  
  53.     strcpy(gstring,argv[1]);
  54.     strcat(gstring,".WAV");
  55.     if((fp=fopen(gstring,"wb"))==0)
  56.     {
  57.         strcpy(gstring,argv[1]);
  58.         if((fp=fopen(gstring,"wb"))==0)
  59.         {
  60.             printf("Error creating .WAV file [%s]\n",argv[1]);
  61.             exit(1);
  62.         }
  63.     }
  64.     printf("FILE: [%s]\n",gstring);
  65.     sbinit();
  66.     dspwrite(0xE1);
  67.     major=dspread();
  68.     minor=dspread();
  69.     printf("DSP version %u.%u\n",major,minor);
  70.     if(major==3)
  71.     {
  72.         outportb(0x224,0x00); outportb(0x225,0xFF);
  73.         outportb(0x224,0x04); outportb(0x225,0x00);
  74.         outportb(0x224,0x0A); outportb(0x225,0x00);
  75.         outportb(0x224,0x0C); outportb(0x225,0x26);
  76.         outportb(0x224,0x0E); outportb(0x225,0x20);
  77.         outportb(0x224,0x22); outportb(0x225,0x99);
  78.         outportb(0x224,0x26); outportb(0x225,0x00);
  79.         outportb(0x224,0x28); outportb(0x225,0x00);
  80.         outportb(0x224,0x2E); outportb(0x225,0x99);
  81.     }
  82.     sbmalloc();
  83.     fLen=16;
  84.     wFormatTag=1;
  85.     nChannels=1;
  86.     nAvgBytesPerSec=0;
  87.     dLen=65000;
  88.     rLen=20+fLen+dLen;
  89.  
  90.     rID=0x46464952;
  91.     fwrite(&rID,1,4,fp);
  92.     fwrite(&rLen,1,4,fp);
  93.     wID=0x45564157;
  94.     fwrite(&wID,1,4,fp);
  95.     fID=0x20746D66;
  96.     fwrite(&fID,1,4,fp);
  97.     fwrite(&fLen,1,4,fp);
  98.     fwrite(&wFormatTag,1,2,fp);
  99.     fwrite(&nChannels,1,2,fp);
  100.     fwrite(&nSamplesPerSec,1,2,fp);
  101.     fwrite(&nAvgBytesPerSec,1,2,fp);
  102.     fwrite(&nSamplesPerSec,1,2,fp);
  103.     ra=0; fwrite(&ra,1,2,fp);
  104.     ra=1; fwrite(&ra,1,2,fp);
  105.     ra=8; fwrite(&ra,1,2,fp);
  106.     dID=0x61746164;
  107.     fwrite(&dID,1,4,fp);
  108.     fwrite(&dLen,1,4,fp);
  109.  
  110.     ca=256UL-(1000000UL/nSamplesPerSec);
  111.     printf("Time Constant %u\n",ca);
  112.     sbsettc(ca);
  113.     sbrec(dLen);
  114.     printf("Recording %lu samples\n",dLen);
  115. //  while(1) if(dmacount()==0xFFFF) break;
  116.     dmastatus();
  117.     while(!dmastatus()) continue;
  118.     fwrite(aligned,1,dLen,fp);
  119.     if(major==3)
  120.     {
  121.         outportb(0x224,0x2E); outportb(0x225,0x00);
  122.     }
  123. }
  124. //------------------------------------------------------------------------------
  125. // Copyright (c) David Welch, 1993
  126. //------------------------------------------------------------------------------
  127.  
  128.